#include "AppRateCollector.mqh"


AppRateCollector::AppRateCollector()
{
}

AppRateCollector::~AppRateCollector()
{
}

AppRateCollector::OnInit()
{
   printf("AppRateCollector: Init");
   int max_count = 1024 * 10;
   m_pipe.Init("127.0.0.1", 9000);
   
   printf("Connected!");
   GetRateInfoReq rateInfoReq;
   rateInfoReq.Init(m_pipe);
   rateInfoReq.GetRateInfo();
   
   RateDataCollector collector;
   MqlRates rates[];
	int rate_count;
	int rateCount = 1024;
	collector.Init(rateInfoReq.SymbolName, rateInfoReq.TimeFrame);
   collector.GetByTime(rates, rate_count, rateInfoReq.StartTime, rateInfoReq.EndTime);
   
   
   SendRateReq sndRateReq;
   sndRateReq.Init(m_pipe);
   
   int remain = rate_count;
   int send_count;
   int sta_pos = 0;
   while(true)
   {
      if(remain > max_count)
         send_count = max_count;
      else
         send_count = remain;
      
      sndRateReq.SendRate(rates, sta_pos, send_count);
      sta_pos += send_count;
      remain -= send_count;
      if(remain <= 0)
         break;
      
      
   }
   sndRateReq.SendRate(rates, 0, 0);
   printf("Send complete!");
 
     
}

AppRateCollector::OnTick(void)
{

}

AppRateCollector::OnDeinit(void)
{
   m_pipe.Close();
}